<template>
  <div class="purchase-order table-theme">
    <head-title title="订单--订单商品"></head-title>
    <el-card>
      <div class="order_list_head">
        <div class="type-view">
          <div
            class="client-item"
            v-for="(item, index) in classifyList"
            :key="item.index"
            @click="roleType(index)"
            :class="[type == index ? 'client-item-active' : '']"
          >
            {{ item.label }}
          </div>
        </div>
      </div>
      <div class="data-filtering-view">
        <div class="data-filtering-left">
          <p>请选择</p>
          <div class="select-view">
            <el-date-picker
              @change="selectTime"
              v-model="time"
              type="daterange"
              align="right"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="pickerOptions"
              value-format="yyyy-MM-dd"
              style="width: 250px;"
            ></el-date-picker>
            <el-select v-model="confirmType" placeholder="请选择确认类型" clearable style="margin-left: 15px; width: 180px" @change="init(1)">
              <!-- <el-option label="待商家确认" :value="1"></el-option> -->
              <el-option label="待平台确认" :value="2"></el-option>
              <el-option label="待工厂确认" :value="7"></el-option>
            </el-select>
            <span style="padding: 0 10px;">预计发货时间</span>
            <el-date-picker
              @change="selectSendTime"
              v-model="sendTime"
              type="daterange"
              align="right"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
              style="width: 250px;"
            ></el-date-picker>
            <el-select v-model="notice_status" placeholder="通知状态筛选" clearable filterable @change="init(1)" style="margin-left: 15px; width: 180px">
              <el-option label="未通知发货" :value="0"></el-option>
              <el-option label="已通知发货" :value="1"></el-option>
            </el-select>
          </div>
        </div>
        <div class="data-filtering-right">
          <el-button type="primary" @click="offlineExport" style="margin-right: 15px;">导出</el-button>
          <search-view
            :option="searchOption"
            @value="goSearch"
            @clear="refreshPage"
          ></search-view>
          <refresh-button @refresh="refreshPage"></refresh-button>
        </div>
      </div>
      <el-table :data="list" stripe style="margin-top: 20px">
        <el-table-column
          label="序号"
          align="center"
          prop="rec_id"
          width="80"
        ></el-table-column>
        <el-table-column
          label="订单号"
          align="center"
          prop="order_sn"
          width="130"
        ></el-table-column>
        <el-table-column
          label="店铺编号"
          align="center"
          width="80"
          prop="store_id"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="店铺名称"
          align="center"
          width="120"
          prop="store_name"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="收货人"
          align="center"
          width="120"
          prop="accept_name"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="收货电话"
          align="center"
          width="120"
          prop="mobile_phone"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="收货地址"
          align="center"
          min-width="200"
          prop="address"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="下单时间"
          align="center"
          width="160"
          prop="add_time"
        ></el-table-column>
        <el-table-column
          label="预计发货时间"
          align="center"
          width="160"
          prop="estimate_time"
        ></el-table-column>
        <el-table-column
          label="工厂编号"
          align="center"
          width="120"
          prop="factory_sn"
        ></el-table-column>
        <el-table-column
          label="工厂名称"
          align="center"
          width="120"
          prop="factory_name"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="商品编号"
          align="center"
          width="120"
          prop="goods_sn"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="商品sku编号"
          align="center"
          width="120"
          prop="sku_sn"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="商品名称"
          align="center"
          width="120"
          prop="goods_name"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="品类"
          align="center"
          width="120"
          prop="class_name"
        ></el-table-column>
        <el-table-column label="主图" align="center" width="80">
          <template slot-scope="scope">
            <el-image :src="scope.row.img" style="width: 50px; height: 50px"></el-image>
          </template>
        </el-table-column>
        <el-table-column label="颜色" align="center" prop="color"></el-table-column>
        <el-table-column label="材质" align="center" prop="lining"></el-table-column>
        <el-table-column label="尺寸" align="center" prop="size"></el-table-column>
        <el-table-column label="是否定制" align="center" width="100" prop="is_customized"></el-table-column>
        <el-table-column label="数量" align="center" prop="goods_number"></el-table-column>
        <el-table-column label="工厂价" align="center" prop="factory_price"></el-table-column>
        <el-table-column label="拿货价" align="center" prop="self_price"></el-table-column>
        <el-table-column
          label="商品备注"
          align="center"
          width="200"
          prop="brief"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="订单备注"
          align="center"
          width="200"
          prop="order_brief"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="后台备注"
          align="center"
          width="200"
          prop="inside_remark"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column label="包件数" align="center" width="100">
          <template slot-scope="scope">{{ scope.row.goods_pack }}件</template>
        </el-table-column>
        <el-table-column label="体积" align="center" width="100">
          <template slot-scope="scope">{{ scope.row.goods_bulk }}m³</template>
        </el-table-column>
        <el-table-column
          label="发货时间"
          align="center"
          width="160"
          prop="express_time"
        ></el-table-column>
        <el-table-column label="发货凭证" align="center" width="80">
          <template slot-scope="scope">
            <template v-if="scope.row.express_img && scope.row.express_img.length">
              <el-image :src="scope.row.express_img" style="width: 50px; height: 50px" v-for="(data,index) in scope.row.express_img" :key="index"></el-image>
            </template>
            <template v-else>--</template>
          </template>
        </el-table-column>
        <el-table-column label="状态" align="center" prop="status_name" width="100"></el-table-column>
        <el-table-column label="生产状态" align="center" width="100">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.produce_status == 0">{{ scope.row.produce_status_name }}</el-tag>
            <el-tag type="success" v-if="scope.row.produce_status == 1">{{ scope.row.produce_status_name }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="商家运营跟单" align="center" prop="service_name" min-width="120"></el-table-column>
        <el-table-column label="工厂跟单" align="center" prop="follow_user"></el-table-column>
        <el-table-column label="操作" align="center" width="80" fixed="right">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="goDetail(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pages">
        <el-pagination
          background
          layout="prev, pager, next, jumper"
          :total="total"
          @current-change="init()"
          :current-page.sync="page"
        ></el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      type: 0,
      classifyList: [
        {
          label: "全部",
          value: "",
          param: {}
        },
        {
          label: "待确认",
          value: 1,
          param: {
            order_status: 0,
            shipping_status: 0,
            pay_status: 2,
            waite_status: '1,2,3'
          }
        },
        {
          label: "待付款",
          value: 2,
          param: {
            order_status: 0,
            shipping_status: 0,
            pay_status: 0,
          }
        },
        {
          label: "待付尾款",
          value: 3,
          param: {
            order_status: 0,
            shipping_status: 0,
            pay_status: 3,
          }
        },
        {
          label: "待发货",
          value: 4,
          param: {
            order_status: 0,
            shipping_status: 0,
            pay_status: 2,
          }
        },
        {
          label: "待收货",
          value: 5,
          param: {
            order_status: 0,
            shipping_status: 1,
            pay_status: 2,
          }
        },
        {
          label: "已完成",
          value: 6,
          param: {
            order_status: 1,
            shipping_status: 2,
            pay_status: 2,
          }
        },
        {
          label: "已取消",
          value: 7,
          param: {
            order_status: 2,
          }
        },
        {
          label: "售后中",
          value: 8,
          param: {
            order_status: '0,1',
            shipping_status: 2,
            pay_status: 2,
            after_sale: '1,2'
          }
        },
      ],
      searchOption: [
        {
          value: 0,
          label: "订单编号",
          key: 'order_sn',
        },
        {
          value: 1,
          label: "店铺名称",
          key: 'store_name',
        },
        {
          value: 2,
          label: "店铺编号",
          key: 'store_id',
        },
        {
          value: 3,
          label: "工厂编号",
          key: 'factory_sn',
        },
        {
          value: 4,
          label: "工厂名称",
          key: 'factory_name',
        },
        {
          value: 5,
          label: "商品编号",
          key: 'goods_sn',
        },
        {
          value: 6,
          label: "商品SKU编号",
          key: 'sku_sn',
        },
        {
          value: 7,
          label: "运营跟单员",
          key: 'service_name',
        },
        {
          value: 8,
          label: "工厂跟单员",
          key: 'follow_user',
        },
      ],
      confirmType: '',
      searchType: "",
      searchContent: "",
      time: [],
      sendTime: [],
      page: 1,
      total: 0,
      list: [],
      notice_status: ''
    };
  },
  watch: {
    showDialog(n,o){
      if(!n){
        this.storageForm = this.$options.data().storageForm
      }
    }
  },
  mounted(){
    this.init()
  },
  methods: {
    init(type) {
      if(type){
        this.page = 1
      }
      let data = {
        notice_status: this.notice_status,
        page: this.page - 1,
        status: this.confirmType,
        start_time: this.time && this.time.length?this.time[0]:'',
        end_time: this.time && this.time.length?this.time[1]:'',
        express_start_time: this.sendTime && this.sendTime.length?this.sendTime[0]:'',
        express_end_time: this.sendTime && this.sendTime.length?this.sendTime[1]:'',
        ...this.classifyList[this.type].param
      }
      if(this.searchType!==''){
        data[this.searchOption[this.searchType].key] = this.searchContent
      }
      this.$http(this.$ApiList.OrderGoodsList,data).then(res => {
        if(res.code==200){
          this.list = res.datas.data
          this.total = res.datas.count
        }
      })
    },
    goSearch(searchType, searchContent) {
      this.searchType = searchType;
      this.searchContent = searchContent;
      this.init(1);
    },
    // 刷新
    refreshPage() {
      this.searchType = 0;
      this.searchContent = "";
      this.init(1);
    },
    selectTime() {
      this.init(1);
    },
    selectSendTime() {
      this.init(1);
    },
    roleType(index) {
      this.type = index;
      this.init(1)
    },
    goDetail(row){
      this.$router.push(`/goods_details?type=1&id=${row.goods_id}`)
    },
    offlineExport() {
      let param = {
        status: this.confirmType,
        start_time: this.time && this.time.length?this.time[0]:'',
        end_time: this.time && this.time.length?this.time[1]:'',
        ...this.classifyList[this.type].param
      }
      if(this.searchType!==''){
        param[this.searchOption[this.searchType].key] = this.searchContent
      }
      let paramString = Object.keys(param).map(key => `${key}=${param[key]}`).join('&')
      console.log(paramString)
      window.location.href = `${this.$domain}furniture/Adminexcel/GetOrderGoodsExcel?${paramString}`
    },
  },
};
</script>

<style lang="scss">
.vl-notify{
	z-index: 10000;
}
</style>
<style lang="scss" scoped>
.order_list_head {
  display: flex;
}
.type-view {
  display: flex;
  flex: 1;
  min-width: 0;
}
.type-view .client-item {
  margin-right: 40px;
  line-height: 40px;
  color: rgba(153, 153, 153, 1);
  cursor: pointer;
}
.client-item-active {
  color: #333333 !important;
  border-bottom: 4px solid #34a1e0;
}
.data-filtering-view {
  margin-top: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .data-filtering-left {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    .select-view {
      margin-left: 10px;
    }
  }
  .data-filtering-right {
    display: flex;
    align-items: center;
  }
}
.storage-info{
  line-height: 30px;
  margin-bottom: 15px;
  font-size: 12px;
  p{
    color: #333;
    font-weight: bold;
    span{
      font-weight: normal;
      color: #888;
    }
  }
}
</style>